package beautiful.butterfly.distributed_service_container.http.handlers.notchange;

import io.netty.channel.ChannelProgressiveFuture;
import io.netty.channel.ChannelProgressiveFutureListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.RandomAccessFile;


//
public class FileChannelProgressiveFutureListener implements ChannelProgressiveFutureListener
{
    private static final Logger log = LoggerFactory.getLogger(System.class);
    private RandomAccessFile randomAccessFile;

    public FileChannelProgressiveFutureListener(RandomAccessFile randomAccessFile)
    {
        this.randomAccessFile = randomAccessFile;
    }

    public static FileChannelProgressiveFutureListener build(RandomAccessFile randomAccessFile)
    {
        return new FileChannelProgressiveFutureListener(randomAccessFile);
    }

    @Override
    public void operationProgressed(ChannelProgressiveFuture channelProgressiveFuture, long progress, long total)
    {
    }

    @Override
    public void operationComplete(ChannelProgressiveFuture channelProgressiveFuture)
    {
        try
        {
            this.randomAccessFile.close();
        } catch (Exception e)
        {
            log.error("RandomAccessFile close error", e);
        }
    }

}